59B - Fortune Telling - CodeForces Solution


implementation number theory *1200

Please click on ads to support us..

Python Code:


def solve():
    n = int(input().strip())
    arr = list(map(int, input().split()))
    arr.sort(reverse=True)

        petals= sum(arr)
        if petals%2 != 0:
        print(petals)
        return petals
        else:
        for i in range(n-1, -1,-1):
            if arr[i] % 2 != 0:
                print(petals- arr[i])
                return petals- arr[i]
        print(0)
    return 0
solve()

C++ Code:

#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define f first
#define s second
#define ou ||
#define dbg(x) cout << #x << " = " << x << endl
#define forn(i, n) for (int i = 0; i < int(n); i++)
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
 
using namespace std;


int main(){_
    int n; cin>>n;
    vector<int> impar, par;
    while(n--){
        int num;cin>>num;
        if(num%2==0) par.push_back(num);
        else impar.push_back(num);
    }
    int saida =0;
    sort(impar.begin(), impar.end(), greater<>());
    sort(par.begin(), par.end(), greater<>());
    int quantos = par.size();
    if(impar.size()!=0){
        if(impar.size()%2==0){
        for(int i=0; i < impar.size() - 1; i++){
            saida+=impar[i];
        }
        for(int i =0 ; i < par.size(); i++){
            saida+=par[i];
        }
    }else{
        for(int i = 0; i < impar.size(); i++){
            saida+=impar[i];
        }
        for(int i =0 ; i < par.size(); i++){
            saida+=par[i];
        }
    }
    }
    
    cout<<saida<<endl;
}


Comments

Submit
0 Comments
More Questions

Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup